const char* PIXEL_SHADER_LANCZOS4 =
"static const float2 INPUT_SIZE = float2(480.0f, 272.0f);\n"
"static const float2 HALF_PIXEL = float2(0.5f, 0.5f);\n"
"static const float PI = 3.141592653589793238462643383f;\n"
"static const float EPS = 1e-6;\n"
"\n"
"sampler2D textureSampler;\n"
"float2 outputSize;\n"
"\n"
"float sinc(float x) {\n"
"return sin(PI * x) / (PI * x);\n"
"}\n"
"\n"
"float lanczos4(float x) {\n"
"if (x < EPS) {\n"
"return 1.0;\n"
"}\n"
"return sinc(x) * sinc(x * 0.25);\n"
"}\n"
"\n"
"float4 rgb(float inputX, float inputY) {\n"
"return tex2D(textureSampler, (float2(inputX, inputY) + HALF_PIXEL) / INPUT_SIZE);\n"
"}\n"
"\n"
"float4 interpolateHorizontally(float2 inputPos, int2 inputPosFloor, int dy) {\n"
"float sumOfWeights = 0.0f;\n"
"float4 sumOfWeightedPixel = 0.0f;\n"
"\n"
"float x;\n"
"float weight;\n"
"\n"
"x = inputPos.x - (inputPosFloor.x - 3);\n"
"weight = lanczos4(x);\n"
"sumOfWeights += weight;\n"
"sumOfWeightedPixel += weight * rgb(inputPosFloor.x - 3, inputPosFloor.y + dy);\n"
"\n"
"--x;\n"
"weight = lanczos4(x);\n"
"sumOfWeights += weight;\n"
"sumOfWeightedPixel += weight * rgb(inputPosFloor.x - 2, inputPosFloor.y + dy);\n"
"\n"
"--x;\n"
"weight = lanczos4(x);\n"
"sumOfWeights += weight;\n"
"sumOfWeightedPixel += weight * rgb(inputPosFloor.x - 1, inputPosFloor.y + dy);\n"
"\n"
"--x;\n"
"weight = lanczos4(x);\n"
"sumOfWeights += weight;\n"
"sumOfWeightedPixel += weight * rgb(inputPosFloor.x + 0, inputPosFloor.y + dy);\n"
"\n"
"x = 1.0f - x;\n"
"weight = lanczos4(x);\n"
"sumOfWeights += weight;\n"
"sumOfWeightedPixel += weight * rgb(inputPosFloor.x + 1, inputPosFloor.y + dy);\n"
"\n"
"++x;\n"
"weight = lanczos4(x);\n"
"sumOfWeights += weight;\n"
"sumOfWeightedPixel += weight * rgb(inputPosFloor.x + 2, inputPosFloor.y + dy);\n"
"\n"
"++x;\n"
"weight = lanczos4(x);\n"
"sumOfWeights += weight;\n"
"sumOfWeightedPixel += weight * rgb(inputPosFloor.x + 3, inputPosFloor.y + dy);\n"
"\n"
"++x;\n"
"weight = lanczos4(x);\n"
"sumOfWeights += weight;\n"
"sumOfWeightedPixel += weight * rgb(inputPosFloor.x + 4, inputPosFloor.y + dy);\n"
"\n"
"return sumOfWeightedPixel / sumOfWeights;\n"
"}\n"
"\n"
"float4 process(float2 outputPos : VPOS) : COLOR0 {\n"
"float2 inputPos = outputPos / outputSize * INPUT_SIZE;\n"
"int2 inputPosFloor = (int2)inputPos;\n"
"\n"
"// Vertical interporation\n"
"float sumOfWeights = 0.0;\n"
"float4 sumOfWeightedPixel = 0.0;\n"
"\n"
"float weight;\n"
"float y;\n"
"\n"
"y = inputPos.y - (inputPosFloor.y - 3);\n"
"weight = lanczos4(y);\n"
"sumOfWeights += weight;\n"
"sumOfWeightedPixel += weight * interpolateHorizontally(inputPos, inputPosFloor, -3);\n"
"\n"
"--y;\n"
"weight = lanczos4(y);\n"
"sumOfWeights += weight;\n"
"sumOfWeightedPixel += weight * interpolateHorizontally(inputPos, inputPosFloor, -2);\n"
"\n"
"--y;\n"
"weight = lanczos4(y);\n"
"sumOfWeights += weight;\n"
"sumOfWeightedPixel += weight * interpolateHorizontally(inputPos, inputPosFloor, -1);\n"
"\n"
"--y;\n"
"weight = lanczos4(y);\n"
"sumOfWeights += weight;\n"
"sumOfWeightedPixel += weight * interpolateHorizontally(inputPos, inputPosFloor, +0);\n"
"\n"
"y = 1.0f - y;\n"
"weight = lanczos4(y);\n"
"sumOfWeights += weight;\n"
"sumOfWeightedPixel += weight * interpolateHorizontally(inputPos, inputPosFloor, +1);\n"
"\n"
"++y;\n"
"weight = lanczos4(y);\n"
"sumOfWeights += weight;\n"
"sumOfWeightedPixel += weight * interpolateHorizontally(inputPos, inputPosFloor, +2);\n"
"\n"
"++y;\n"
"weight = lanczos4(y);\n"
"sumOfWeights += weight;\n"
"sumOfWeightedPixel += weight * interpolateHorizontally(inputPos, inputPosFloor, +3);\n"
"\n"
"++y;\n"
"weight = lanczos4(y);\n"
"sumOfWeights += weight;\n"
"sumOfWeightedPixel += weight * interpolateHorizontally(inputPos, inputPosFloor, +4);\n"
"\n"
"return float4((sumOfWeightedPixel / sumOfWeights).xyz, 1.0f);\n"
"}\n"
;
